﻿/*****************************************************
**Copyright(C), 2021-2022, Ciqtek Technology.
**Version:     2.0
**Author:      hujiarui
**Date:        2023/06/28
**Description: 基类Item派生类，角度
*****************************************************/

#ifndef ANGLEGRAPHICSITEM_H
#define ANGLEGRAPHICSITEM_H

#include "../../ofuidll_global.h"

#include "BaseGraphicsItem.h"

namespace OfUI {

	class OFUIDLL_EXPORT AngleGraphicsItem : public BaseGraphicsItem
	{
		Q_OBJECT
			Q_INTERFACES(QGraphicsItem)

	public:
		/**
		 * @brief  选择类型
		 */
		enum SelectType
		{
			SELECT_NONE = 0,        ///< 未选择
			SELECT_FIRST_POINT,     ///< 选择第一个点
			SELECT_SECOND_POINT,    ///< 选择第二个点
			SELECT_THIRD_POINT,     ///< 选择第三个点
			SELECT_ALL              ///< 选择整体
		};

	public:
		/**
		 * @brief  AngleGraphicsItem 构造函数
		 * @param  parent
		 * @return
		 */
		AngleGraphicsItem(QGraphicsItem *parent = 0);

		/**
		 * @brief  ~AngleGraphicsItem 析构函数
		 * @return
		 */
		virtual ~AngleGraphicsItem();

	public:
		/**
		 * @brief  setAnglePoint 设置点
		 * @param  firstPoint
		 * @param  secondPoint
		 * @param  thirdPoint
		 * @return void
		 */
		void setAnglePoint(const QPointF& firstPoint, const QPointF& secondPoint, const QPointF& thirdPoint);

		/**
		 * @brief  getFirstPoint 获取第一个点
		 * @return QPointF
		 */
		QPointF getFirstPoint() const;

		/**
		 * @brief  getSecondPoint 获取第二个点
		 * @return QPointF
		 */
		QPointF getSecondPoint() const;

		/**
		 * @brief  getThirdPoint 获取第三个点
		 * @return QPointF
		 */
		QPointF getThirdPoint() const;

	public:
		/**
		 * @brief  isAdding 判断是否正在添加
		 * @return bool
		 */
		bool isAdding() const override;

		/**
		 * @brief  isEditing 判断是否正在编辑
		 * @return bool
		 */
		bool isEditing() const override;

		/**
		 * @brief  isVaild 判断是否有效
		 * @return bool
		 */
		bool isVaild() const override;

		/**
		 * @brief  select 坐标选择拖拽类型
		 * @param  point
		 * @param  selType
		 * @return BaseGraphicsItem::MouseDragType
		 */
		MouseDragType select(const QPointF& point, int* selType = nullptr) const override;

		/**
		 * @brief  cursor 坐标位置设置光标
		 * @param  point
		 * @param  cursor
		 * @return void
		 */
		void cursor(const QPointF& point, QCursor& cursor) const override;

		/**
		 * @brief  mousePressEvent 鼠标按下事件
		 * @param  event
		 * @return void
		 */
		void mousePressEvent(QGraphicsSceneMouseEvent *event) override;

		/**
		 * @brief  mouseReleaseEvent 鼠标弹起事件
		 * @param  event
		 * @return void
		 */
		void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;

		/**
		 * @brief  mouseMoveEvent 鼠标移动事件
		 * @param  event
		 * @return void
		 */
		void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;

		/**
		 * @brief  focusOutEvent 失焦事件
		 * @param  event
		 * @return void
		 */
		void focusOutEvent(QFocusEvent *event) override;

	protected:
		/**
		 * @brief  boundingRect 重写boundingRect
		 * @return QRectF
		 */
		QRectF boundingRect() const override;

		/**
		 * @brief  paint 重写paint
		 * @param  painter
		 * @param  option
		 * @param  widget
		 * @return void
		 */
		void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget /* = nullptr */) override;

	protected:
		/** 角度坐标
		 */
		QPointF m_firstPoint;
		QPointF m_secondPoint;
		QPointF m_thirdPoint;

		/** 是否正在添加
		 */
		bool m_bAdding;

		/** 选择类型
		 */
		SelectType m_eSelType;

		/** 鼠标按下位置
		 */
		QPointF m_pressMousePos;
	};

}

#endif // ANGLEGRAPHICSITEM_H
